//
//  XMLMessageModel.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/4/12.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "XMLMessageModel.h"
#import "XXTool.h"

@implementation XMLMessageModel

+(void)requestMessageListWithAcceptType:(NSString *)aType
                              listCount:(NSInteger)count
                             completion:(void (^)(BOOL, NSMutableArray<XMLMessageModel *> *,NSInteger))block
{
    [DKHTTPRequest sendNewDataWithShortUrl:@"msg_list_2017_"
                                  Param:[XXTool formatStringWithLanguage:[NSString stringWithFormat:@"userid=%@&passwd=%@&accept=%@&nstart=%ld&ntotal=10",[UserInfo shareUserInfo].userID,[UserInfo shareUserInfo].userPassword,aType,(long)count]]
                             ImageArray:nil
                                TimeOut:10
                             Completion:^BOOL(NSMutableDictionary *serverDic, DKHTTPResponseType bufferType) {
                                 if ([[serverDic objectForKey:@"code"] intValue]==200)
                                 {
                                     NSMutableArray *dataList = [[NSMutableArray alloc] init];
                                     if ([[serverDic objectForKey:@"total"] intValue]!=0)
                                     {
                                         NSArray *list = [serverDic objectForKey:@"list"];
                                         for (int i=0; i<list.count; i++)
                                         {
                                             XMLMessageModel *temp = [XMLMessageModel modelWithDictionary:list[i]];
                                             [dataList addObject:temp];
                                         }
                                     }
                                     block(YES,dataList,[[serverDic objectForKey:@"havelookcount"] integerValue]);
                                 }
                                 else
                                 {
                                     block(NO,nil,0);
                                     
                                 }
                                 return YES;
                             } IsBuffering:YES
                      IsNeedReplaceWrap:NO
                        IsUseUpLoadHead:NO];
}

+(void)requestMessageLiuyanListWithAcceptType:(NSInteger)count
                             completion:(void (^)(BOOL, NSMutableArray<XMLMessageModel *> *))block{
    [DKHTTPRequest sendNewDataWithShortUrl:@"messageboard_list_2017_"
                                     Param:[XXTool formatStringWithLanguage:[NSString stringWithFormat:@"userid=%@&passwd=%@&nstart=%ld&ntotal=10",[UserInfo shareUserInfo].userID,[UserInfo shareUserInfo].userPassword,(long)count]]
                                ImageArray:nil
                                   TimeOut:10
                                Completion:^BOOL(NSMutableDictionary *serverDic, DKHTTPResponseType bufferType) {
                                    if ([[serverDic objectForKey:@"code"] intValue]==200)
                                    {
                                        NSMutableArray *dataList = [[NSMutableArray alloc] init];
                                        
                                            NSArray *list = [serverDic objectForKey:@"list"];
                                            for (int i=0; i<list.count; i++)
                                            {
                                                XMLMessageModel *temp = [XMLMessageModel modelWithDictionary:list[i]];
                                                [dataList addObject:temp];
                                            }
                                        
                                        block(YES,dataList);
                                    }
                                    else
                                    {
                                        block(NO,nil);
                                        
                                    }
                                    return YES;
                                } IsBuffering:YES
                         IsNeedReplaceWrap:NO
                           IsUseUpLoadHead:NO];
}

@end
